/**
 * Copyright &copy; com.smooth.common
 */
package com.smooth.site.sx.mag.biz.applyjob.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.smooth.common.site.common.PageDb;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.smooth.dao.gen.bean.BizJobApplay;
import com.smooth.dao.gen.bean.BizJobApplayExample;
import com.smooth.dao.gen.BizJobApplayMapper;
import com.smooth.common.site.common.enums.DelFlagEnums;
import com.smooth.common.site.common.persistence.Page;
import com.smooth.common.site.common.utils.IdGenerater;

/**
 * 职位申请Service
 * @author bm
 * @version 2019-02-10
 */
@Service
@Transactional(readOnly = true)
public class BizJobApplayService{
	Logger log = LoggerFactory.getLogger(BizJobApplayService.class);
	@Autowired
	BizJobApplayMapper bizJobApplayMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizJobApplay get(String no) {
		return bizJobApplayMapper.selectByPrimaryKey(no);
	}
	
	public List<BizJobApplay> findList(BizJobApplay bizJobApplay) {
		BizJobApplayExample bizJobApplayExample = new BizJobApplayExample();
		BizJobApplayExample.Criteria criteria = bizJobApplayExample.createCriteria();
		
		return bizJobApplayMapper.selectByExample(bizJobApplayExample);
	}
	
	public Page<BizJobApplay> findPage(Page<BizJobApplay> page, BizJobApplay bizJobApplay) {
		BizJobApplayExample bizJobApplayExample = new BizJobApplayExample();
		BizJobApplayExample.Criteria criteria = bizJobApplayExample.createCriteria();
		
		bizJobApplayExample.setPage(page);
		
		List<BizJobApplay> dlist = bizJobApplayMapper.selectByExample(bizJobApplayExample);
		page.setList(dlist);
		page.setCount(bizJobApplayMapper.countByExample(bizJobApplayExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public BizJobApplay save(BizJobApplay bizJobApplay) {
		if(StringUtils.isNotEmpty(bizJobApplay.getId())&&get(bizJobApplay.getId())!=null) {
			int optNum = bizJobApplayMapper.updateByPrimaryKeySelective(bizJobApplay);
			if(optNum==1) {
				log.info("更新 student 数据【"+bizJobApplay.toString()+"】成功");
			}else {
				log.error("更新 student 数据【"+bizJobApplay.toString()+"】失败");
			}
			return bizJobApplayMapper.selectByPrimaryKey(bizJobApplay.getId());
		}else {
			Date date = new Date();
			bizJobApplay.setCreateDate(date);
			bizJobApplay.setId(idGenerater.genClsNo("bizJobApplay"));
			bizJobApplay.setUpdateDate(date);
			int optNum =  bizJobApplayMapper.insertSelective(bizJobApplay);
			if(optNum==1) {
				log.info("插入 student 数据【"+bizJobApplay.toString()+"】成功");
			}else {
				log.error("插入 student 数据【"+bizJobApplay.toString()+"】失败");
			}
			return bizJobApplay;
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizJobApplay bizJobApplay) {
		bizJobApplayMapper.deleteByPrimaryKey(bizJobApplay.getId());
	}
	
}